package com.example.androidshixun.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.androidshixun.R;
import com.example.androidshixun.bean.Exercise;

import java.util.ArrayList;
import java.util.List;

public class Tab2Fragment extends Fragment {

    private List<Exercise> exerciseList = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_tab_2_layout, container, false);

            ListView listView = view.findViewById(R.id.list);

            initExercise();

            ExerciseAdapter adapter = new ExerciseAdapter(exerciseList, getContext());
            listView.setAdapter(adapter);
            return view;
    }

    private void initExercise() {
        Exercise exercise;
        exerciseList.clear();
        for(int i=0; i<20; ++i) {
            exercise = new Exercise();
            exercise.id = i;
            exercise.title = "第 " + (i+1) +  "章";
            exercise.color = i%4;
            exercise.url = "https://ks.wjx.top/vj/Pp4rufh.aspx";
            exerciseList.add(exercise);
        }
    }
}
